package com.his.modules.sysjob.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.his.core.entity.R;
import com.his.modules.sysjob.entity.SysJobLog;
import com.his.modules.sysjob.service.impl.SysJobLogServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * 调度日志操作处理
 */
@RestController
@RequestMapping("/sysjoblog")
public class SysJobLogController
{
    @Resource
    private SysJobLogServiceImpl sysJobLogService;

    @GetMapping("/page")
    public R<Object> list(Page page, SysJobLog sysJobLog)
    {
		QueryWrapper<SysJobLog> queryWrapper = new QueryWrapper<>();
		queryWrapper.like("job_name", sysJobLog.getJobName() == null?"" : sysJobLog.getJobName());
		queryWrapper.orderByDesc("create_time");
        return R.ok(sysJobLogService.page(page, queryWrapper));
    }

    @DeleteMapping("/remove")
    public R<Object> remove(@RequestBody Map<String, String> param)
    {
		String ids = param.getOrDefault("ids", "");
        return R.ok(sysJobLogService.removeByIds(Arrays.asList(StringUtils.split(ids, ","))));
    }

    @DeleteMapping("/clean")
    public R<Object> clean()
    {
		SysJobLog sysJobLog = new SysJobLog();
        return R.ok(sysJobLog.delete(new QueryWrapper<>()));
    }
}